<?php

namespace frontend\controllers;

use Yii;
use yii\web\Controller;
use yii\helpers\Url;
use frontend\models\ecwapi\util\CommonUtil;
use tengze\weixinhelper\WeiXinHelper;

/**
 * @author Randy <zhangshi3421@gmail.com>
 */
class BaseController extends Controller {
  public $noNeedAuth = array();

  public function beforeAction($action) {
    $session = Yii::$app->session;
    if (YII_DEBUG) {
      //XXX 此处可以做一些测试环境登陆判断，session判断等的逻辑
      return parent::beforeAction($action);
    } else {
      //XXX 此处可以做一些正式环境登陆判断，session判断等的逻辑
      return parent::beforeAction($action);
    }
  }

  public function renderWithWXAbility($viewName, $params=[]) {
    $params["wxparam"] = [
      //XXX 此处的debug注意正式环境要变成false，或者不写
      "debug" => "true",
      //XXX jsApiList可以根据项目实际需要进行删减
      "jsApiList" => ['checkJsApi',
          'onMenuShareTimeline',
          'onMenuShareAppMessage',
          'onMenuShareQQ',
          'onMenuShareWeibo',
          'onMenuShareQZone',
          'hideMenuItems',
          'showMenuItems',
          'hideAllNonBaseMenuItem',
          'showAllNonBaseMenuItem',
          'translateVoice',
          'startRecord',
          'stopRecord',
          'onVoiceRecordEnd',
          'playVoice',
          'onVoicePlayEnd',
          'pauseVoice',
          'stopVoice',
          'uploadVoice',
          'downloadVoice',
          'chooseImage',
          'previewImage',
          'uploadImage',
          'downloadImage',
          'getNetworkType',
          'openLocation',
          'getLocation',
          'hideOptionMenu',
          'showOptionMenu',
          'closeWindow',
          'scanQRCode',
          'chooseWXPay',
          'openProductSpecificView',
          'addCard',
          'chooseCard',
          'openCard']
    ];
    $params["wxcontext"] = new WeiXinHelper();
    $view = $this->render($viewName, $params);
    return $view;
  }
}
?>
